//
//  UIImageView+WebImage.swift
//  TYCWeiBo
//
//  Created by 中发 on 2018/6/12.
//  Copyright © 2018年 中发. All rights reserved.
//

import SDWebImage

extension UIImageView {
    
    /// 隔离SDWebimage。设置图像函数
    ///
    /// - Parameters:
    ///   - urlString: urlString
    ///   - placeholderImage: 占位图像
    func tempSetImage(urlString: String?, placeholderImage: UIImage?, isAvart: Bool = false) {
        
        guard let urlString = urlString,let url = URL(string: urlString) else {
            image = placeholderImage
            return
        }
        
        //可选项只用在Swift，OC中有时候用！同样可以传入nil
        sd_setImage(with: url, placeholderImage: placeholderImage, options: [], progress: nil) { [weak self] (image, _, _, _) in
            //完成回调，判断是否有头像
            if isAvart {
                self?.image = image?.tempAvartImage(size: self?.bounds.size)
            }
        }
    }
    
}
